import React from 'react';
import { useKeycloak } from '@react-keycloak/web';
import ProductList from './ProductList'; // 假设ProductList组件在同一个目录下


function App() {
  const { keycloak, initialized } = useKeycloak();

  if (!initialized) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <p>User is {keycloak.authenticated ? 'Authenticated' : 'Not Authenticated'}</p>
      {keycloak.authenticated && (
        <div>
          <p>Welcome, {keycloak.tokenParsed.preferred_username}</p>
          <button onClick={() => keycloak.logout()}>Logout</button>


          <ProductList />
        </div>
      )}

    </div>
  );
}

export default App;
